<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>登录-统一身份认证</title>
    <link rel="stylesheet" th:href="@{/public/plugins/layui/css/layui.css}" media="all">
    <style>
        .login {
            width: 400px;
            height: 250px;
            position: absolute;
            top: 40%;
            left: 50%;
            /*background-color: #F5F5F5;*/
            border-radius: 5px;
            -webkit-transform: translate(-50%, -50%);
            -moz-transform: translate(-50%, -50%);
            transform: translate(-50%, -50%);
            padding-top: 20px;
            padding-right: 50px;
        }
    </style>
</head>
<body>

<form id="form" class="layui-form login" th:action="@{/login}" method="post">
    <div class="layui-form-item" style="text-align: center;padding-left: 40px;">
        统一身份认证登录
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户名:</label>
        <div class="layui-input-block">
            <input type="text" name="username" required lay-verify="username" placeholder="请输入用户名" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密&nbsp;&nbsp;&nbsp;&nbsp;码:</label>
        <div class="layui-input-block">
            <input type="password" name="password" required lay-verify="password" placeholder="请输入密码" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" style="text-align: center;color: red;">
        <span th:text="${error}"></span>
    </div>

    <div class="layui-form-item" style="text-align: center;padding-left: 40px;">
        <button class="layui-btn" lay-submit lay-filter="go" style="width: 120px">登录</button>
    </div>
</form>

</body>

<script th:src="@{/public/plugins/jquery/jquery.min.js}"></script>
<script th:src="@{/public/plugins/layui/layui.js}"></script>

<script th:inline="javascript">

    if (window != window.top) {
        //替换当前页面内容
        window.top.location.replace(window.location)
    }

    var contextRoot = /*[[@{/}]]*/ '';
    layui.use(['form'], function () {
        var form = layui.form;

        //自定义验证规则
        form.verify({
            username: function (value) {
                if (!value.trim()) {
                    return '请输入用户名';
                }
            }
            , password: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            ,
        });

//        form.on("submit(go)",function (data) {
//            console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
//            console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
//            console.log(data.field)
//            return false;
//        })


    });
</script>

</html>